#include "Tail.h"
#include <iostream>
using namespace std;
using namespace sf;

void Tail::initialize(Vector2f piece, float size, Vector2f direction) {
	lastPoint = piece;
	Vector2f orthogonal = calculateOrthogonalVector(direction);
	orthogonal *= size;
	rightBorder = piece + orthogonal;
	leftBorder = piece - orthogonal;
}

void Tail::addTailPiece(Vector2f piece, float size, Vector2f direction) {
	Shape nextTailPiece;
	Vector2f orthogonal = calculateOrthogonalVector(direction);
	orthogonal *= size;
	nextTailPiece.AddPoint(leftBorder);
	nextTailPiece.AddPoint(rightBorder);
	rightBorder = piece + orthogonal;
	leftBorder = piece - orthogonal;
	nextTailPiece.AddPoint(rightBorder);
	nextTailPiece.AddPoint(leftBorder);
	shape = nextTailPiece;
	lastPoint = piece;
}

Shape Tail::getNewTailPiece() {
	return shape;
}
